package training;

import java.util.Scanner;

public class Day4_02 {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()){
            int m = scanner.nextInt();
            int n = scanner.nextInt();
            String s = "0123456789ABCDEF";
            StringBuilder string = new StringBuilder("");
            boolean flag = false;
            if(m < 0){
                m = -m;
                flag = true;
            }
            while (m != 0){
                string.append(s.charAt(m % n));
                m /= n;
            }
            if(flag){
                string.append("-");
            }
            string.reverse();
            System.out.println(string);
        }
    }
}
